<template>
  <div class="JADP-common-layout">
    <div class="JADP-common-layout-center">
      <el-row class="JADP-common-search-box" :gutter="16">
        <el-form @submit.native.prevent>
          <el-col :span="6">
            <el-form-item label="班级编号">
              <el-input v-model="query.clazzno" placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="班级名称">
              <el-input
                v-model="query.classname"
                placeholder="请输入"
                clearable
              >
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="报名时间">
              <el-date-picker
                v-model="query.signupdate_start"
                placeholder="请选择"
                value-format="timestamp"
                type="date"
                clearable
              />
            </el-form-item>
          </el-col>
          <template v-if="showAll">
            <el-col :span="6">
              <el-form-item label="报名结束时间">
                <el-date-picker
                  v-model="query.signupdate_end"
                  placeholder="请选择"
                  value-format="timestamp"
                  type="date"
                  clearable
                />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="培训类别">
                <el-select
                  v-model="query.train_type"
                  placeholder="请选择"
                  clearable
                >
                  <el-option
                    v-for="(item, index) in getDict('pxlb')"
                    :key="index"
                    :label="item.dataName"
                    :value="item.id"
                    :disabled="item.disabled"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="行业类型">
                <el-select
                  v-model="query.categorytype"
                  placeholder="请选择"
                  clearable
                >
                  <el-option
                    v-for="(item, index) in getDict('hangye')"
                    :key="index"
                    :label="item.dataName"
                    :value="item.id"
                    :disabled="item.disabled"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <!-- <el-col :span="6">
              <el-form-item label="所属低地区">
                <el-select v-model="query.area" placeholder="请选择" clearable>
                  <el-option
                    v-for="(item, index) in getDict('suozaidiqu')"
                    :key="index"
                    :label="item.dataName"
                    :value="item.id"
                    :disabled="item.disabled"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col> -->
          </template>
          <el-col :span="6">
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" @click="search()"
                >查询</el-button
              >
              <el-button icon="el-icon-refresh-right" @click="reset()"
                >重置</el-button
              >
              <el-button
                type="text"
                icon="el-icon-arrow-down"
                @click="showAll = true"
                v-if="!showAll"
              >
                展开
              </el-button>
              <el-button
                type="text"
                icon="el-icon-arrow-up"
                @click="showAll = false"
                v-else
              >
                收起
              </el-button>
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
      <div class="JADP-common-layout-main JADP-flex-main">
        <div class="JADP-common-head">
          <div>
            <el-button
              type="primary"
              icon="el-icon-plus"
              @click="addOrUpdateHandle()"
              >新增
            </el-button>
          </div>
          <div class="JADP-common-head-right">
            <el-tooltip effect="dark" content="刷新" placement="top">
              <el-link
                icon="icon-ym icon-ym-Refresh JADP-common-head-icon"
                :underline="false"
                @click="reset()"
              />
            </el-tooltip>
            <screenfull :isContainer="true" />
            <el-tooltip effect="dark" content="列设置" placement="top">
              <el-link
                icon="icon-ym icon-ym-options JADP-common-head-icon"
                :underline="false"
              />
            </el-tooltip>
          </div>
        </div>
        <JADP-table
          v-loading="listLoading"
          :data="list"
          @sort-change="sortChange"
        >
          <el-table-column prop="clazzno" label="班级编号" align="left" show-overflow-tooltip/>
          <el-table-column prop="classname" label="班级名称" align="left" show-overflow-tooltip/>

          <el-table-column
            prop="categorytype"
            label="行业类型"
            align="left"
            width="135"
          />
          <el-table-column label="培训类别" prop="train_type" algin="left">
            <template slot-scope="scope">
              {{ getDict("pxlb", scope.row.train_type) }}
            </template>
          </el-table-column>

          <el-table-column
            prop="signupdate_start"
            label="报名开始时间"
            align="left"
          />
          <el-table-column
            prop="signupdate_end"
            label="报名结束时间"
            align="left"
          />
          <el-table-column
            prop="traindate_start"
            label="培训开始时间"
            align="left"
            width="135"
          />
          <el-table-column
            prop="traindate_end"
            label="培训结束时间"
            align="left"
            width="135"
          />
          <el-table-column label="培训方式" prop="train_mode" algin="left">
            <template slot-scope="scope">
              {{ getDict("bjpxfs", scope.row.train_mode) }}
            </template>
          </el-table-column>
          <!-- <el-table-column
            prop="train_duration"
            label="培训时长"
            align="left"
          /> -->
          <el-table-column prop="hours" label="学时" align="left" />
          <el-table-column label="是否发布" align="left">
            <template v-slot="{ row }">
              <el-switch
                v-model="row.area"
                active-color="#13ce66"
                inactive-color="#ff4949"
                @change="switchChange(row)"
              >
              </el-switch>
            </template>
          </el-table-column>
          <!-- <el-table-column label="是否热门" prop="isHottest" algin="left">
            <template slot-scope="scope">
              {{ getDict("Highlytoxicchemicals", scope.row.isHottest) }}
            </template>
          </el-table-column> -->
          <!-- <el-table-column prop="isHottest" width="150px" label="是否热门">
            <template slot-scope="scope">
              {{ getDict("Highlytoxicchemicals", scope.row.isHottest) }}
            </template>
          </el-table-column>
          <el-table-column label="是否最新" prop="isNewtest" algin="left">
            <template slot-scope="scope">
              {{ getDict("Highlytoxicchemicals", scope.row.isNewtest) }}
            </template>
          </el-table-column> -->
          <el-table-column label="操作" fixed="right" width="140">
            <template #default="{ row }">
              <el-button
                type="text"
                @click="addOrUpdateHandle(row.id)"
                v-if="!row.area"
                >编辑
              </el-button>
              <el-button
                type="text"
                @click="addOrUpdateHandle(row.id, true)"
                v-else
                >查看
              </el-button>
              <!-- <el-button type="text" @click="addOrUpdateHandle(row.id)"
                >编辑
              </el-button> -->
              <el-button
                type="text"
                class="JADP-table-delBtn"
                @click="handleDel(row.id)"
                >删除
              </el-button>
              <el-dropdown
                @command="bmRecord"
                trigger="click"
                placement="bottom"
              >
                <span class="el-dropdown-link"
                  >更多<i class="el-icon-arrow-down el-icon--right"></i>
                </span>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item
                    :command="{ name: 'e', id: row.id, area: row.area }"
                    >课程列表</el-dropdown-item
                  >
                  <el-dropdown-item :command="{ name: 'a', id: row.id }"
                    >报名记录</el-dropdown-item
                  >
                  <el-dropdown-item :command="{ name: 'b', id: row.id }"
                    >学习分析</el-dropdown-item
                  >
                  <el-dropdown-item :command="{ name: 'c', id: row.id }"
                    >成绩管理</el-dropdown-item
                  >
                  <el-dropdown-item :command="{ name: 'd', id: row.id }"
                    >考试管理</el-dropdown-item
                  >
                  <el-dropdown-item
                    :command="{
                      name: 'f',
                      id: row.id,
                    }"
                    >学员评价</el-dropdown-item
                  >
                  <el-dropdown-item
                    :command="{
                      name: 'g',
                      id: row.id,
                    }"
                  >
                    学习监控
                  </el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
            </template>
          </el-table-column>
        </JADP-table>
        <pagination
          :total="total"
          :page.sync="listQuery.currentPage"
          :limit.sync="listQuery.pageSize"
          @pagination="initData"
        />
      </div>
    </div>
    <JADP-Form v-if="formVisible" ref="JADPForm" @refresh="refresh" />
    <ExportBox v-if="exportBoxVisible" ref="ExportBox" @download="download" />
    <ImportBox
      v-if="importBoxVisible"
      ref="importBox"
      @refresh="reset()"
      @ImportPreviewApi="ImportPreviewApi"
      @importDataApi="importDataApi"
      @TemplateDownload="TemplateDownload"
      :URL="URL"
    />
    <SignUpRecord
      ref="SignUpRecord"
      v-if="signUpVisible"
      :visible.sync="signUpVisible"
    />
    <RateOfLearning
      ref="rateOfLearning"
      v-if="studyVisible"
      @refresh1="refresh1"
    />
    <Chengjiguanli ref="Chengjiguanli" v-if="scoreVisible" @refresh="refresh" />
    <Shijuanguanli ref="Shijuanguanli" v-if="PaperVisible" @refresh="refresh" />
    <KeChengPeiXun
      ref="KeChengPeiXun"
      v-if="KeChengPeiXunvisible"
      @refresh="refresh"
    />
    <Evaluation
      ref="Evaluation"
      v-if="evaluationVisible"
      @refresh="refresh"
      categore="896b47acaad64ae59d8bcaf86e6fba18"
      :categoretype="1"
    />
    <LearningCenter
      v-if="learningVisible"
      ref="learningCenter"
      @refresh="refresh"
    />
  </div>
</template>

<script>
import request from "@/utils/request";
import { getDictionaryDataSelector } from "@/api/systemData/dictionary";
import JADPForm from "./Form";
import ExportBox from "./ExportBox";
import SignUpRecord from "./signUpRecord.vue";
import RateOfLearning from "./rateOfLearning.vue";
import { previewDataInterface } from "@/api/systemData/dataInterface";
import Chengjiguanli from "./chengjiguanli/index.vue";
import Shijuanguanli from "./shijuanguanli";
import KeChengPeiXun from "./kechengpeixun.vue";
import Evaluation from "./pingjia/evaluation.vue";
import LearningCenter from "./learningCenter";
export default {
  components: {
    JADPForm,
    ExportBox,
    SignUpRecord,
    RateOfLearning,
    Chengjiguanli,
    Shijuanguanli,
    KeChengPeiXun,
    Evaluation,
    LearningCenter,
  },
  data() {
    return {
      //导入属性
      importBoxVisible: false,
      URL: "xy_ks_class_info/Xy_ks_class_info",
      showAll: false,
      signUpVisible: false,
      flag: false,
      query: {
        classname: undefined,
        ischarge: undefined,
        signupdate_start: undefined,
        signupdate_end: undefined,
        train_type: undefined,
        categorytype: undefined,
        area: undefined,
        isAdmin: true,
      },
      defaultProps: {
        children: "children",
        label: "fullName",
      },
      studyVisible: false,
      scoreVisible: false,
      PaperVisible: false,
      KeChengPeiXunvisible: false,
      evaluationVisible: false,
      learningVisible: false,
      list: [],
      listLoading: true,
      total: 0,
      listQuery: {
        currentPage: 1,
        pageSize: 20,
        sort: "desc",
        sidx: "",
      },
      formVisible: false,
      exportBoxVisible: false,
      columnList: [
        { prop: "classname", label: "班级名称" },
        { prop: "categorytype", label: "行业类型" },
        { prop: "train_type", label: "培训类别" },
        { prop: "area", label: "所属低地区" },
        { prop: "signupdate_start", label: "报名开始时间" },
        { prop: "signupdate_end", label: "报名结束时间" },
        { prop: "traindate_start", label: "培训开始时间" },
        { prop: "traindate_end", label: "培训结束时间" },
        { prop: "train_mode", label: "培训方式" },
        { prop: "train_duration", label: "培训时长" },
      ],
      areaOptions: [
        { fullName: "选项一", id: "1" },
        { fullName: "选项二", id: "2" },
      ],
      areaOptions: [
        { fullName: "选项一", id: "1" },
        { fullName: "选项二", id: "2" },
      ],
      train_modeOptions: [
        { fullName: "选项一", id: "1" },
        { fullName: "选项二", id: "2" },
      ],
    };
  },
  computed: {},
  created() {
    this.initData();
    if (this.$route.query.result && JSON.parse(this.$route.query.result)) {
      this.scoreVisible = true;
      this.$nextTick(() => {
        // this.$refs.Chengjiguanli.clazzid = id;
        // this.$refs.Chengjiguanli.paperinit();
        this.$refs.Chengjiguanli.resultFlag = true;
        this.$refs.Chengjiguanli.initData();
      });
    }
  },
  methods: {
    bmRecord(command) {
      let id = command.id;
      if (command.name == "a") {
        this.signUpVisible = true;
        this.$nextTick(() => {
          this.$refs.SignUpRecord.initData(id);
        });
      }
      if (command.name == "b") {
        this.studyVisible = true;
        this.$nextTick(() => {
          this.$refs.rateOfLearning.initData(id);
          this.$refs.rateOfLearning.classInfo(id);
        });
      }
      if (command.name == "c") {
        this.scoreVisible = true;
        this.$nextTick(() => {
          this.$refs.Chengjiguanli.clazzid = id;
          this.$refs.Chengjiguanli.paperinit(id);
        });
      }
      if (command.name == "d") {
        this.PaperVisible = true;
        this.$nextTick(() => {
          this.$refs.Shijuanguanli.clazzid = id;
          this.$refs.Shijuanguanli.initData(id);
        });
      }
      if (command.name == "e") {
        this.KeChengPeiXunvisible = true;
        this.$nextTick(() => {
          this.$refs.KeChengPeiXun.clazzid = id;
          if (command.area) {
            this.$refs.KeChengPeiXun.area = command.area;
          }
          this.$refs.KeChengPeiXun.initData();
        });
      }
      if (command.name == "f") {
        this.evaluationVisible = true;
        this.$nextTick(() => {
          this.$refs.Evaluation.classid = id;
          // this.$refs.Evaluation.initData();
        });
      }
      if (command.name == "g") {
        this.learningVisible = true;
        this.$nextTick(() => {
          this.$refs.learningCenter.initData(id);
        });
      }
    },
    ImportPreviewApi(val) {
      let query = { fileName: val };
      request({
        url: `/api/xy_ks_class_info/Xy_ks_class_info/ImportPreview`,
        method: "get",
        data: query,
      })
        .then((res) => {
          this.$refs.importBox.list = res.data.dataRow;
          this.$refs.importBox.btnLoading = false;
          this.$refs.importBox.active++;
        })
        .catch(() => {
          this.$refs.importBox.btnLoading = false;
        });
    },
    importDataApi(val) {
      let query = { list: val,organizeId :this.$store.getters.organizeId };
      request({
        url: `/api/xy_ks_class_info/Xy_ks_class_info/ImportData`,
        method: "post",
        data: query,
      })
        .then((res) => {
          this.$refs.importBox.result = res.data;
          this.$refs.importBox.resultList = res.data.failResult;
          this.$refs.importBox.btnLoading = false;
          this.$refs.importBox.active++;
        })
        .catch(() => {
          this.$refs.importBox.btnLoading = false;
        });
    },
    TemplateDownload() {
      request({
        url: `/api/xy_ks_class_info/Xy_ks_class_info/templateDownload?organizeId=${this.$store.getters.organizeId}`,
        method: "post",
      }).then((res) => {
        if (!res.data.url) return;
        window.location.href = this.define.comUrl + res.data.url;
      });
    },
    uploadForm() {
      this.importBoxVisible = true;
      this.$nextTick(() => {
        this.$refs.importBox.init(this.columnList);
      });
    },
    sortChange({ column, prop, order }) {
      this.listQuery.sort = order == "ascending" ? "asc" : "desc";
      this.listQuery.sidx = !order ? "" : prop;
      this.initData();
    },
    initData() {
      this.listLoading = true;
      let _query = {
        ...this.listQuery,
        ...this.query,
        isAdmin: true,
        organizeId:this.$store.getters.organizeId
      };
      let query = {};
      for (let key in _query) {
        if (Array.isArray(_query[key])) {
          query[key] = _query[key].join();
        } else {
          query[key] = _query[key];
        }
      }
      request({
        url: `/api/xy_ks_class_info/Xy_ks_class_info`,
        method: "get",
        data: query,
      }).then((res) => {
        this.list = res.data.list;
        this.total = res.data.pagination.total;
        this.listLoading = false;
      });
    },
    handleDel(id) {
      this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        type: "warning",
      })
        .then(() => {
          request({
            url: `/api/xy_ks_class_info/Xy_ks_class_info/${id}`,
            method: "DELETE",
          }).then((res) => {
            this.$message({
              type: "success",
              message: res.msg,
              onClose: () => {
                this.initData();
              },
            });
          });
        })
        .catch(() => {});
    },
    addOrUpdateHandle(id, isDetail) {
      this.formVisible = true;
      this.$nextTick(() => {
        this.$refs.JADPForm.init(id, isDetail);
      });
    },
    exportData() {
      this.exportBoxVisible = true;
      this.$nextTick(() => {
        this.$refs.ExportBox.init(this.columnList);
      });
    },
    download(data) {
      let query = { ...data, ...this.listQuery, ...this.query ,organizeId :this.$store.getters.organizeId};
      request({
        url: `/api/xy_ks_class_info/Xy_ks_class_info/Actions/Export`,
        method: "GET",
        data: query,
      }).then((res) => {
        if (!res.data.url) return;
        window.location.href = this.define.comUrl + res.data.url;
        this.$refs.ExportBox.visible = false;
        this.exportBoxVisible = false;
      });
    },
    search() {
      this.listQuery = {
        currentPage: 1,
        pageSize: 20,
        sort: "desc",
        sidx: "",
      };
      this.initData();
    },
    switchChange(row) {
      // this.$confirm("班级发布后无法编辑和添加课程，你确认发布吗？")
      //   .then(_ => {
      //   })
      //   .catch(_ => {});
      request({
        url: "/api/xy_ks_class_info/Xy_ks_class_info/updateArea/" + row.id,
        method: "put",
        data: {
          area: row.area,
        },
      })
        .then((res) => {
          this.$message({
            duration: 3000,
            message: res.msg,
            type: "success",
          });
        })
        .catch((err) => {
          this.$message({
            duration: 3000,
            message: "班级下暂无课程无法发布",
            type: "warning",
          });
          if (row.area) {
            row.area = false;
          }
        });
    },
    refresh(isrRefresh) {
      this.formVisible = false;
      this.scoreVisible = false;
      this.PaperVisible = false;
      this.KeChengPeiXunvisible = false;
      this.evaluationVisible = false;
      this.learningVisible = false;
      if (isrRefresh) this.reset();
    },
    refresh1(isrRefresh) {
      this.studyVisible = false;
      if (isrRefresh) this.reset();
    },
    reset() {
      for (let key in this.query) {
        this.query[key] = undefined;
      }
      this.listQuery = {
        currentPage: 1,
        pageSize: 20,
        sort: "desc",
        sidx: "",
      };
      this.initData();
    },
  },
};
</script>

<style lang="scss" scoped>
::v-deep .el-dropdown {
  font-size: 12px;
  cursor: pointer;
  margin-top: 0;
  color: #1890ff;
  &:active {
    color: #347abd;
  }
}
::v-deep .el-dropdown-menu--small ::v-deep.el-dropdown-menu__item {
  padding: 0 !important;
}
</style>
